home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************/
- /* */
- /* glue.c - A/ROSE driver serial glue calls. */
- /* */
- /* Richard W. Mincher. February 20, 1990. */
- /* */
- /* Copyright © 1990, Apple Computer, Inc. All rights reserved. */
- /* */
- /********************************************************************************/
-
-
- #include "Types.h"
- #include "Files.h"
- #include "Memory.h"
- #include "OSUtils.h"
- #include "Resources.h"
- #include "Serial.h"
-
- #include "AROSE.h"
- #include "os.h"
- #include "managers.h"
- #include "Download.h"
-
- #include "ARDriver.h"
- #include "ARTask.h"
-
- void
- RxComplete(AROSEmessage *m);
- pascal OSErr
- ARPBControl(ParmBlkPtr pb, short async);
- pascal OSErr
- ARPBStatus(ParmBlkPtr pb, short async);
- pascal OSErr
- ARPBWrite(ParmBlkPtr pb, short async);
- pascal OSErr
- ARPBRead(ParmBlkPtr pb, short async);
-
- pascal OSErr
- AROpenDriver(char *name, short *refNum)
- {
- ParamBlockRec pb;
- AROSEmessage *m;
- short slot, port;
- tid_type tid, nmtid;
- struct ST_PB stpb;
- short smask;
- long rtype;
- char fname[65];
- short namelen;
- SysEnvRec se;
- short rfNum, saverf, i;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
-
- *refNum = 0;
- SysEnvirons( curSysEnvVers, &se );
-
- if (OpenQueue( 0 ) == 0)
- {
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- return (-26); /* ERROR - couldn't open queue */
- }
-
- //
- // Get file name. Read up to ":".
- //
-
- i = name[0];
- for(namelen = 1; namelen < i; namelen++)
- {
- if (name[namelen] == ':')
- break;
- fname[namelen-1] = name[namelen];
- }
-
- if (namelen == i)
- {
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- CloseQueue();
- return (-26); /* ERROR - Couldn't parse filename */
- }
-
- fname[namelen-1] = 0;
-
- //
- // Get resource name.
- //
-
- for(i=0; i < 4; i++)
- ((char *)&rtype)[i] = name[namelen+1+i];
-
- //
- // Get slot number and port.
- //
-
- slot = -1;
- port = -1;
- if (name[namelen+5] == '9')
- slot = 9;
- else if ((name[namelen+5] >= 'A') && (name[namelen+5] <= 'E'))
- slot = name[namelen+5] - 'A' + 10;
- else if ((name[namelen+5] >= 'a') && (name[namelen+5] <= 'e'))
- slot = name[namelen+5] - 'a' + 10;
-
- if ((name[namelen+6] >= '0') && (name[namelen+6] <= '9'))
- port = name[namelen+6] - '0';
-
- //
- // Validate port and slot by checking to see if the card is a Livonia card and
- // if the driver for that port is already running.
- //
-
- saverf = CurResFile();
- c2pstr( fname );
- rfNum = OpenRFPerm( fname, se.sysVRefNum, fsRdPerm );
- if (rfNum == -1)
- {
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- CloseQueue();
- return (-26); /* ERROR - Couldn't open file */
- }
-
- if ((port == -1) || (slot == -1) || (GetResource(rtype, 0) == 0))
- {
- CloseResFile( rfNum );
- UseResFile( saverf );
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- CloseQueue();
- return (-26); /* ERROR - invalid Slot/Port */
- }
-
- smask = 1 << slot;
- (void)NewFindcard( &smask, 0 );
- if (!smask)
- {
- CloseResFile( rfNum );
- UseResFile( saverf );
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- CloseQueue();
- return (-26); /* ERROR - not MCP card */
- }
-
- stpb.stack = 4096;
- stpb.heap = 0;
- stpb.priority = 28;
- stpb.ParentTID = 0;
- stpb.InitRegs.D_Registers[7] = port;
-
- //
- // Try to do dynamic download of driver. If it fails we probably have to boot
- // the card.
- //
-
- tid = DynamicDownload(slot, rtype, &stpb, name, name[0]+1 );
- if (!tid)
- {
- //
- // Download the generic AROSE stuff to the card. We'll get the name manager tid.
- // We should do this ONLY if AROSE is not already running.
- //
-
- nmtid = StartAROSE( slot );
- if (!nmtid)
- {
- CloseResFile( rfNum );
- UseResFile( saverf );
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- CloseQueue();
- return (-26); /* ERROR - AROSE not started */
- }
-
- //
- // Now we download the serial driver to the card. D7 will be set up to point to
- // the port number.
- //
-
- tid = DynamicDownload(slot, rtype, &stpb, name, name[0] + 1);
- if (!tid)
- {
- CloseResFile( rfNum );
- UseResFile( saverf );
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- CloseQueue();
- return (-26); /* ERROR - Serial driver not loaded */
- }
- }
-
- CloseResFile( rfNum );
- UseResFile( saverf );
-
- //
- // Hit task with hammer to wake it up and open the driver.
- //
-
- m = GetMsg();
- m->mTo = tid;
- m->mCode = SNBOpen;
- m->mSData[0] = (unsigned long)&pb;
- pb.ioParam.ioResult = 1;
- pb.ioParam.ioCompletion = 0;
- Send( m );
- (void)Receive( 0, 0, 0, 0, (ProcPtr)StripAddress((Ptr)RxComplete) );
- while(pb.ioParam.ioResult > 0)
- PushAIPC();
- *refNum = (slot << 12) + (port << 7);
- return (pb.ioParam.ioResult);
- }
-
- pascal OSErr
- ARCloseDriver(short refNum)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
- AROSEmessage *m;
- struct globals *g;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- g = (struct globals *)(((refNum & 0xF000) << 8) +
- (refNum & 0x0180) + 0x200);
- SetMyTid(g->hisTid);
- m = GetMsg();
- m->mTo = (tid_type)(g->myTid);
- m->mFrom = (tid_type)(g->hisTid);
- m->mCode = SNBClose;
- m->mSData[0] = (unsigned long)&pb;
- pb.ioParam.ioResult = 0;
- pb.ioParam.ioCompletion = 0;
- Send( m );
- CloseQueue();
- return (pb.ioParam.ioResult);
- }
-
- pascal OSErr
- ARKillIO(short refNum)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 1;
- pb.cntrlParam.ioCRefNum = refNum;
- return (ARPBControl( &pb, 0 ));
- }
-
- pascal OSErr
- ARSerReset(short refNum, short serConfig)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 8;
- pb.cntrlParam.csParam[0] = serConfig;
- pb.cntrlParam.ioCRefNum = refNum;
- return (ARPBControl( &pb, 0 ));
- }
-
- pascal OSErr
- ARSerSetBuf(short refNum, char *serBPtr, short serBLen)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 9;
- pb.cntrlParam.csParam[0] = ((unsigned long)serBPtr >> 16) & 0xFFFF;
- pb.cntrlParam.csParam[1] = (unsigned long)serBPtr & 0xFFFF;
- pb.cntrlParam.csParam[2] = serBLen;
- pb.cntrlParam.ioCRefNum = refNum;
- return (ARPBControl( &pb, 0 ));
- }
-
- pascal OSErr
- ARSerHShake(short refNum, SerShk *flags)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
- short i;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 10;
- pb.cntrlParam.ioCRefNum = refNum;
- for(i=0; i < sizeof(SerShk); i++)
- ((char *)(pb.cntrlParam.csParam))[i] = ((char *)flags)[i];
- return (ARPBControl( &pb, 0 ));
- }
-
- pascal OSErr
- ARSerSetBrk(short refNum)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 12;
- pb.cntrlParam.ioCRefNum = refNum;
- return (ARPBControl( &pb, 0 ));
- }
-
- pascal OSErr
- ARSerClrBrk(short refNum)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 11;
- pb.cntrlParam.ioCRefNum = refNum;
- return (ARPBControl( &pb, 0 ));
- }
-
- pascal OSErr
- ARSerGetBuf(short refNum, long *count)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 2;
- pb.cntrlParam.ioCRefNum = refNum;
- (void)ARPBStatus( &pb, 0 );
- *count = ((pb.cntrlParam.csParam[0] << 16) | pb.cntrlParam.csParam[1]);
- return (pb.ioParam.ioResult);
- }
-
- pascal OSErr
- ARSerStatus(short refNum, SerStaRec *serSta)
- {
- #pragma unused(refNum)
- ParamBlockRec pb;
- short i;
-
- #ifdef DEBUG
- Debugger();
- #endif DEBUG
- pb.cntrlParam.ioResult = 1;
- pb.cntrlParam.ioCompletion = 0;
- pb.cntrlParam.csCode = 8;
- pb.cntrlParam.ioCRefNum = refNum;
- (void)ARPBStatus( &pb, 0 );
- for(i=0; i < sizeof(SerStaRec); i++)
- ((char *)serSta)[i] = ((char *)(pb.cntrlParam.csParam))[i];
- return (pb.ioParam.ioResult);
- }
-
-